package org.jshand.homework;

import java.util.Scanner;

/**
 * @author 金山
 * 项目：javase
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2024/10/1714:42
 */
public class Manager {
    private  Student[] stus = new Student[30];
    private int size = 0;
    Scanner scanner = new Scanner(System.in);

    //属性

    //方法  (普通、构造方法)

    public void addStudent(){
        // 1  请输入姓名、性别、成绩
        System.out.println("请输入姓名");
        String name = scanner.next();

        System.out.println("请输入性别");
        String gender = scanner.next();

        System.out.println("请输入成绩");
        double score = scanner.nextDouble();

        Student student = new Student(name,gender,score);
        stus[ size++] = student;
        // 添加到 数组中
        System.out.println("添加成功");
    }

    public void updateScore(){
        //1 把所有学生列举出来
        showAllStudent();

        /**
         * 1  张三
         * 2 李四
         */
        // 2 请选择更新那个序号的学会   index(1\2)

        System.out.println("请选择更新学生的序号");
        int index = scanner.nextInt();


        //接受输入  数字
        //3 获取要修改的学生
        // Student updateSt = stus[index];
        //4  请输入姓名、性别、成绩
        System.out.println("请输入姓名");
        String name = scanner.next();

        System.out.println("请输入性别");
        String gender = scanner.next();

        System.out.println("请输入成绩");
        double score = scanner.nextDouble();

        stus[index] = new Student(name,gender,score);


        // 5 updateSt.setName  setGedner  setScore

        System.out.println("更新成功");
        showAllStudent();
    }


    public void  showAllStudent(){
        //遍历数据

        for (int i = 0; i < size; i++) {

            stus[i].introduce(i);
            // System.out.println(i+"\t"+stus[i]);
        }

    }


    /**
     * 选择菜单
     * @return
     */
    public int  showMenu(){
        System.out.println("\r\n\r\n请选择菜单");
        System.out.println("1、新增学生 addStudent(Student stu)\n" +
                "2、修改学生成绩 updateScore(String name, double score)\n" +
                "3、查看所有学生信息的方法 showAllStudent0) \n" +
                "4、退出");
        int selectMenu = new Scanner(System.in).nextInt();


        return  selectMenu;
    }

    public static void main(String[] args) {

        Manager manager = new Manager();
        int selectMenu=    -1;
        while ((selectMenu = manager.showMenu()) != 4){
            switch (selectMenu){
                case 1:
                    manager.addStudent();
                    break;
                case 2:
                    manager.updateScore();
                    break;
                case 3:
                    manager.showAllStudent();
                    break;
            }
        }
    }
}
